package cn.luoyifan.mq._05_topics;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/** 生产者
 * 1.创建连接
 * 2.创建通道
 * 3.创建fanout交换机
 * 4.发送消息
 * /

 /** 消费者
 * 1.创建连接
 * 2.创建通道
 * 3.创建队列
 * 4.绑定队列到交换机
 * 5.监听队列
 * 6.处理消息
 */

//生产者
public class Producer {
    // 队列名字
    public static final String QUEUE_FANOUT_LUOYIFAN = "QUEUE_FANOUT_LUOYIFAN";

    public static void main(String[] args) throws IOException, TimeoutException {
        //1.创建连接
        ConnectionFactory factory = new ConnectionFactory();
//        factory.setHost("115.159.88.63");
//        factory.setUsername(userName);
//        factory.setPassword(password);
//        factory.setVirtualHost(virtualHost);
//        factory.setHost(hostName);
//        factory.setPort(portNumber);
        Connection connection = factory.newConnection();
        //2.创建通道
        Channel channel = connection.createChannel();

        // 3.创建fanout交换机
        channel.exchangeDeclare(QUEUE_FANOUT_LUOYIFAN,"生产者1");

        //4.发送消息
        channel.basicPublish("",QUEUE_FANOUT_LUOYIFAN,null,"请求集合！".getBytes());
        System.out.println("消息发送完毕");

        Connection conn = factory.newConnection();
    }
}
